using System;
using System.Windows.Forms;
using BTSProjectWizard.Forms;
using System.Collections;
using System.Diagnostics;
namespace BTSProjectWizard
{
	
	public class UIUtil
	{
		private UIUtil(){}
		public static bool Run(Wizard wiz,int hwnd)
		{
			PageContainer pc = new PageContainer();
			BTSWizardPage page = null;
			ArrayList al  = new ArrayList();
			string typeName;
			if(wiz.Info.Pages.Count>0)
			{
				for(int i=0;i<wiz.Info.Pages.Count;i++)
				{
					
					typeName = wiz.Info.Pages[i].TypeName;
					Debug.WriteLine(typeName);
					Type t  = Type.GetType(typeName);
					if(t==null)
					{
						throw new Exception(String.Format("Unable to load type {0}",typeName));
					}
					page = (BTSWizardPage)Activator.CreateInstance(t);
					page.Title = wiz.Info.Pages[i].Title;
					page.Data = wiz.Info.Pages[i].Data;
					al.Add(page);
				}
				BTSWizardPage[] pages = (BTSWizardPage[])Array.CreateInstance(typeof(BTSWizardPage),al.Count);
				al.CopyTo(pages);
				IntPtr ip = (IntPtr)hwnd;
				DialogResult dr = pc.Show(pages,ip);
				if(dr==DialogResult.Cancel||dr==DialogResult.Abort||dr==DialogResult.Ignore)
					return false;
				else
					return true;
			}
			return true;
		} 
		
	}
}
